/*
 * @Author: wwssaabb
 * @Date: 2021-12-16 10:21:08
 * @LastEditTime: 2021-12-16 11:17:14
 * @FilePath: \handwritten-code\main\字符串转驼峰.js
 */

/* 
  字符串转驼峰，例如
  foo bar   => fooBar
  foo-bar-- => fooBar
  foo_bar__ => fooBar
*/

function camelCase(str) {
  const reg = /[-_\s]+(.)?/g
  return str.replace(reg, (_, char) => char ? char.toUpperCase() : '')
}


console.log(camelCase('foo bar'))
console.log(camelCase('foo_bar__'))
console.log(camelCase('foo-bar--'))